package cn.campus.exception;

import cn.campus.exception.article.ArticleException;
import cn.campus.pojo.article.vo.ResultVO;
import cn.campus.util.ResultVoUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 全局异常处理器
 * Created by linyanbin on 2018/9/19.
 */
@ControllerAdvice
public class GloableExceptionHandler {

    @ExceptionHandler({ArticleException.class})
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ResponseBody
    public ResultVO<Object> handlerException(ArticleException e) {
        return ResultVoUtils.error(e.getCode(), e.getMessage());
    }

}
